// 双端队列
// Created by FanGccU on 2025/6/22.
// 适用于频繁插入和删除的场景

#include <deque>
#include <iostream>
using namespace std;

int main(int argc, char *argv[]) {
    deque<int> d;

    // 向尾部追加元素
    d.push_back(1);
    d.push_back(2);
    d.push_back(3);

    // 向头部插入元素
    d.push_front(4);

    cout << "d values: \t";
    for (int i: d) {
        cout << i << "\t";
    }
    cout << endl;

    // 移除头部和尾部的元素
    d.pop_front();
    d.pop_back();

    cout << "remove element d values: \t";
    for (int i: d) {
        cout << i << "\t";
    }
    cout << endl;

    // 修改头和尾的数据
    cout << "head data value:\t"<< d.front() << endl;
    cout << "tail data value:\t"<< d.back() << endl;

    d.front() = 11;
    d.back() = 22;

    cout << "head data value:\t"<< d.front() << endl;
    cout << "tail data value:\t"<< d.back() << endl;

}
